package com.ruoyi.web.controller.workSafetyStandardization.rule;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.workSafetyStandardization.domain.GradeRule;
import com.ruoyi.workSafetyStandardization.service.IGradeRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评分-评级得分规则Controller
 *
 * @author pengjie
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/secure/securerule/gradeRule")
public class GradeRuleController extends BaseController
{
    @Autowired
    private IGradeRuleService gradeRuleService;

    /**
     * 查询评分-评级得分规则列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(GradeRule gradeRule, @Param("pageSize") String pageSize, @Param("pageNum") String pageNum)
    {
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(pageSize));
        List<GradeRule> list = gradeRuleService.selectGradeRuleList(gradeRule);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeRule:list')")
    @GetMapping("/queryAll")
    public AjaxResult queryAll(GradeRule gradeRule)
    {
        return success(gradeRuleService.selectGradeRuleList(gradeRule));
    }

    /**
     * 导出评分-评级得分规则列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeRule:export')")
    @Log(title = "评分-评级得分规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GradeRule gradeRule)
    {
        List<GradeRule> list = gradeRuleService.selectGradeRuleList(gradeRule);
        ExcelUtil<GradeRule> util = new ExcelUtil<GradeRule>(GradeRule.class);
        util.exportExcel(response, list, "评分-评级得分规则数据");
    }

    /**
     * 获取评分-评级得分规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeRule:query')")
    @GetMapping(value = "/{gradeRuleId}")
    public AjaxResult getInfo(@PathVariable("gradeRuleId") String gradeRuleId)
    {
        return success(gradeRuleService.selectGradeRuleByGradeRuleId(gradeRuleId));
    }

    /**
     * 新增评分-评级得分规则
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeRule:add')")
    @Log(title = "评分-评级得分规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GradeRule gradeRule)
    {
        gradeRule.setGradeRuleId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(gradeRuleService.insertGradeRule(gradeRule));
    }

    /**
     * 修改评分-评级得分规则
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeRule:edit')")
    @Log(title = "评分-评级得分规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GradeRule gradeRule)
    {
        return toAjax(gradeRuleService.updateGradeRule(gradeRule));
    }

    /**
     * 删除评分-评级得分规则
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeRule:remove')")
    @Log(title = "评分-评级得分规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradeRuleIds}")
    public AjaxResult remove(@PathVariable String[] gradeRuleIds)
    {
        return toAjax(gradeRuleService.deleteGradeRuleByGradeRuleIds(gradeRuleIds));
    }
}
